package com.test.deencredit.dialog_deencredit;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.test.deencredit.R;
import com.test.deencredit.activity_deencredit.LoginActivity_deencredit;
import com.test.deencredit.config_deencredit.UserState_deencredit;
import com.test.deencredit.util_deencredit.UserInfoUtil_deencredit;
import com.test.deencredit.util_deencredit.http_deencredit.HttpUtil_deencredit;


public class LogoutDialog_deencredit extends Dialog {

    private final String page_deencredit = "DIALOG_LOGOUT";

    public LogoutDialog_deencredit(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_logout_deencredit);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(true);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        initView_deencredit();
    }

    @SuppressLint("SetTextI18n")
    private void initView_deencredit(){

        findViewById(R.id.dlo_tv_cancel).setOnClickListener(v -> {
            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"CANCEL_CLICK","");
            dismiss();
        });

        findViewById(R.id.dlo_tv_logout).setOnClickListener(v -> {

            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"LOGOUT_CLICK","");

            UserInfoUtil_deencredit.getInstance_deencredit().clear_deencredit();
            UserState_deencredit.clearState_deencredit();

            dismiss();

            Intent intent = new Intent(getContext(), LoginActivity_deencredit.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            getContext().startActivity(intent);

        });

    }

    @Override
    public void show() {
        super.show();
        HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"START","");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"END","");

    }
}
